﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PirateBayDownloader
{
    public static class StringExtensions
    {
        public static List<string> FindAllBetween(this String data, string from, string to)
        {
            List<string> results = new List<string>();

            int startIndex = data.IndexOf(from);
            while (startIndex != -1)
            {
                int endIndex = data.IndexOf(to, startIndex + from.Length);
                if (endIndex == -1)
                {
                    return results;
                }
                results.Add(data.Substring(startIndex, endIndex - startIndex + to.Length));
                startIndex = data.IndexOf(from, endIndex + to.Length);
            }



            return results;
        }

        public static String FindBetween(this String data, string from, string to)
        {

            int startIndex = data.IndexOf(from);
            if (startIndex == -1) return "";
            int endIndex = data.IndexOf(to, startIndex + from.Length);

            if (endIndex == -1) return "";

            return data.Substring(startIndex, endIndex - startIndex + to.Length);
        }


    }
}
